const app = getApp();
const api = app.globalData.api


Page({
    data: {
        passRateCurve: {
            lazyLoad: true
        },
        analysisRate: {
            lazyLoad: true
        },
        active: true,
        passRateRateRange: '',
        analysisRateRange: ''
    },
    onLoad: async function () {
        await this.getAnalysis()
        await this.getPassRate()
    },
    onChange: async function (obj) {
        const type = obj.detail.name
        await this.getAnalysis({type: type})
        await this.getPassRate({type: type})
    },
    // 不良原因分析
    getAnalysis: async function (params = {}) {
      let that = this
      const res = await api.curlPost('?cla=purchaseStatistics&fun=getAnalysis', params)
      if (res.code === 1) {
          that.setData({
            analysisRateRange: res.data.dateRange
          })
          return api.wxCharts(that.selectComponent('#analysisRateCurve'), api.lineChart({
            title: res.data.title,
            series: res.data.series,
            xData: res.data.data,
          }))
      }
    },
    // 合格率曲线
    getPassRate: async function (params = {}) {
        let that = this
        const res = await api.curlPost('?cla=purchaseStatistics&fun=qualityRate', params)
        if (res.code === 1) {
            that.setData({
              passRateRateRange: res.data.dateRange
            })
            return api.wxCharts(that.selectComponent('#passRateCurve'), api.lineChart({
              title: res.data.title,
              series: res.data.series,
              xData: res.data.data,
            }))
        }
    },
})